Skip to content

Add non-blocking task.IsCompleted check - #182

Open
andystaples wants to merge 7 commits into
mainfrom
andystaples/add-nonblocking-task-completion
Open

andystaples wants to merge 7 commits into
mainfrom
andystaples/add-nonblocking-task-completion

Conversation

@andystaples

Copy link
Copy Markdown
Contributor

Fixes #177.

Summary

Adds task.IsCompleted(t Task) bool, a non-blocking check for whether an orchestration task has completed. A task counts as completed when it succeeded, failed, or was canceled. The check doesn't block, consume the result, or advance history. Call Await to read the result or error.

Behavior

  • Replay position. The check reflects the current replay position, not every event already in history. Completions are applied one at a time. When WhenAny or Select wakes on a completion, only the selected task is guaranteed to be complete. Other completions in the same batch become visible after the orchestration waits again.
  • No yielding. Polling never yields to the orchestration scheduler, so a loop that only polls never lets a task finish. Use Await, WhenAny, or Select to wait.
  • Compatibility. The Task interface is unchanged, so existing Task implementations keep compiling.
  • Unsupported calls panic. Nil and custom Task implementations panic, matching OnTask, WhenAny, and Select. Calls outside an orchestration coroutine panic, matching Select.

WhenAll still accepts custom tasks while the other helpers reject them. That existing inconsistency is tracked separately in #181 and is out of scope here.

Analyzer

The orchestratorgo analyzer treats task.IsCompleted as a pure read instead of possible durable progress. It also reports for !task.IsCompleted(t) loops it can prove never make durable progress. The report requires t to be a local variable that the loop never reassigns, whose address is never taken, and that no closure captures. Compound conditions aren't reported.

Sample and docs

  • The externalevents sample checks for a Stop event between typed checkpoint receives. A stop request doesn't interrupt a checkpoint wait that is already pending; the sample README points to Select for that case.
  • Updated the root README, the analyzer README, the samples README, and the CHANGELOG.

Add task.IsCompleted, which reports whether an orchestration task has
succeeded, failed, or been canceled without blocking, consuming its
result, or advancing history. The Task interface is unchanged. Custom
Task implementations are rejected as in OnTask, and calls outside an
orchestration coroutine panic as in Select.

Teach the orchestratorgo analyzer that IsCompleted is a pure read and
report !task.IsCompleted(t) loops that can never make durable progress.

Show a between-checkpoint stop check in the externalevents sample.

Fixes #177

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 18, 2026 22:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues remain for the task completion API and related analyzer updates.

No open issues 🎉

What changed in this PR

Adds task.IsCompleted(t) so orchestrators can check task completion without blocking, consuming results, or advancing history, while preserving the existing Task interface.

Changes:

  • Adds the completion check with tests for outcomes, unsupported calls, and replay-position behavior.
  • Updates the analyzer to recognize completion checks as pure reads and flag provably non-progressing polling loops.
  • Demonstrates stop checks between checkpoints in the external-events sample and documents the API’s limitations.
File Description
task/​task.go Implements and documents IsCompleted.
task/​task_completion_test.go Tests completion states, panic conditions, and replay behavior.
samples/​README.md Adds task readiness to the external-events sample description.
samples/​externalevents/​README.md Explains checkpoint-boundary stop handling.
samples/​externalevents/​externalevents.go Demonstrates non-blocking stop checks between checkpoints.
samples/​externalevents/​externalevents_test.go Tests stop ordering and checkpoint errors.
README.md Introduces the completion check and polling limitations.
cmd/​orchestratorvet/​README.md Documents polling-loop diagnostics and proof constraints.
cmd/​orchestratorvet/​analysis/​orchestratorgo/​testdata/​src/​loops/​loops.go Adds polling-loop diagnostic and exclusion cases.
cmd/​orchestratorvet/​analysis/​orchestratorgo/​testdata/​src/​github.com/​microsoft/​durabletask-go/​task/​task.go Adds the API stub for analyzer tests.
cmd/​orchestratorvet/​analysis/​orchestratorgo/​loops.go Detects non-progressing polling loops and models IsCompleted as pure.
cmd/​orchestratorvet/​analysis/​orchestratorgo/​checks.go Passes syntax context into loop analysis.
CHANGELOG.md Records the new API and analyzer behavior.

Review effort: Balanced

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 20, 2026 17:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

There are no active review issues for the non-blocking task completion API and related polling diagnostics.

No open issues 🎉

Review effort: Balanced

@berndverst Bernd Verst (berndverst) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IsCompleted adds the readiness check without changing Task or advancing history. I would fix the polling diagnostic before merging: a Go iterator can await durable work and still be reported as a loop that can never make progress.

andystaples and others added 2 commits November 23, 2026 12:13
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 23, 2026 19:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The range analysis misses implicit calls through generic iterators, causing false non-yielding diagnostics even when an iterator awaits a durable task.

1 open issue

Review effort: Balanced

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 23, 2026 20:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the non-blocking task completion API and related analyzer changes.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@berndverst Bernd Verst (berndverst) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The direct and generic iterator fixes address the original examples, and IsCompleted preserves the existing Task interface and replay behavior. There is one more false positive: slices.Collect can run an iterator that awaits durable work, but vet still reports that the loop cannot make progress.

andystaples and others added 2 commits November 23, 2026 16:48
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The callback guard can falsely report yielding polling loops as non-yielding when trusted package calls dispatch user-defined methods, requiring conservative handling and regression coverage.

1 open issue

Review effort: Balanced

Comment on lines +244 to +245
if isFunction(argumentType) || isTypeParameter(argumentType) {
return true

@berndverst Bernd Verst (berndverst) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The iterator fixes now cover direct ranges, generic ranges, and slices.Collect. I reproduced the remaining issue in the method-dispatch thread: fmt.Sprint can call a String method that awaits durable work, but vet still reports that the loop cannot make progress. The diagnostic should stay conservative when a call can invoke user methods.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose a non-blocking task completion check

3 participants